package net.meblabs.bookapp.data.model;

import java.util.Collection;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;

import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@Entity
public class Author {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	@NotEmpty(message = "{notempty.author.fname}")
	private String fname;
	@NotEmpty(message = "{notempty.author.lname}")
	private String lname;
	@Past(message = "{past.author.birthDate}")
	@NotNull(message = "{notnull.author.birthDate}")
	@DateTimeFormat(pattern = "dd-MM-YYYY")
	private Date birthDate;
	@ManyToMany(targetEntity = Book.class, mappedBy = "authors")
	private Collection<Book> books;
}
